<template>
    <div>
        <div class="section">
            <div class="location">
                <span>当前位置：</span>
                <a href="/index.html">首页</a> &gt;
                <a href="/login.html">会员登录</a>
            </div>
        </div>
        <div class="section">
            <div class="wrapper">
                <div class="bg-wrap">
                    <div class="nav-tit">
                        <a class="selected" href="javascript:;">账户登录</a>
                        <i>|</i>
                        <a href="/register.html">免费注册</a>
                    </div>

                    <div id="loginform" name="loginform" class="login-box">
                        <div class="input-box">
                            <input id="txtUserName" ref="userNameRef" name="txtUserName" type="text" placeholder="用户名/手机/邮箱" maxlength="50">
                        </div>
                        <div class="input-box">
                            <input id="txtPassword" ref="passWordRef" name="txtPassword" type="password" placeholder="输入登录密码" maxlength="16">
                        </div>
                        <div class="btn-box">
                            <input id="btnSubmit" @click="login" name="btnSubmit" type="submit" value="立即登录">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

import bus from '../../common/commom.js'
import {ISLOGIN} from '../../common/commom.js'

export default {
    methods:{
        login(){
            const url = `site/account/login`
            
            const params = {user_name:this.$refs.userNameRef.value,password:this.$refs.passWordRef.value}

            this.$axios.post(url,params).then(response =>{
                if(response.data.status===1){
                    this.$message.error(response.data.message)
                    return
                }
            })
            
            //直接设置写法
            // bus.$emit("hasLogin",true)
            //按需导出组件 写法
            bus.$emit(ISLOGIN,true)

            this.$router.push({path:localStorage.getItem("lastVisitPath")})
            console.log(localStorage.getItem('lastVisitPath'))
            console.log('111111')

        }
    }

}
</script>

